Skip to content

[WC-3362] Charts: Add refresh interval to list-based charts - #2486

Open
yordan-st wants to merge 10 commits into
mainfrom
feat/WC-3362_charts-refresh-interval
Open

yordan-st wants to merge 10 commits into
mainfrom
feat/WC-3362_charts-refresh-interval

Conversation

@yordan-st

@yordan-st yordan-st commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Pull request type

New feature (non-breaking change which adds functionality)


Description

Brings back the "Refresh time (in seconds)" option for charts, as documented for classic charts. Charts aggregating view entities otherwise never refresh without a page reload.

  • Adds a refreshInterval property (default 0 = off) to Area, Bar, Bubble, Column, Heat map, Line, Pie/Doughnut and Time series charts. Custom chart is out of scope (attribute-based data, not a list data source).
  • A shared useRefreshInterval hook in @mendix/shared-charts reloads every data source the chart renders after the interval. It restarts the timer on each data update and skips sources that are still loading, matching Datagrid 2 and Gallery. The chart keeps showing its current data during the reload.
  • Unit tests for the hook (including a StrictMode remount case) and a LineChart integration test. CHANGELOG entries for all 8 widgets.

Docs: the property is new in widget XML, so https://docs.mendix.com/refguide/charts-configuration/ may need a mendix/docs update.

What should be covered while testing?

  • Line chart on a view entity (or an entity editable from a second tab), static series, Refresh time = 5: change data elsewhere, chart updates within ~5 s
  • During the reload the chart keeps showing the previous data (no flash of an empty chart)
  • Refresh time = 0: no automatic update
  • Repeat with a Pie chart (single data source) and a chart with one static plus one dynamic series
  • Studio Pro: the property appears under General > Data source for all 8 charts and not for Custom chart
  • No errors in the DevTools console

@yordan-st yordan-st changed the title [WC-3362]: Add refresh interval to list-based charts [WC-3362] Charts: Add refresh interval to list-based charts Oct 22, 2026
@yordan-st
yordan-st force-pushed the feat/WC-3362_charts-refresh-interval branch from 4862ba8 to a022cb2 Compare October 22, 2026 09:25
@yordan-st
yordan-st marked this pull request as ready for review October 22, 2026 09:29
@yordan-st
yordan-st requested a review from a team as a code owner October 22, 2026 09:29
@yordan-st
yordan-st force-pushed the feat/WC-3362_charts-refresh-interval branch from a022cb2 to 2422da6 Compare October 22, 2026 09:29
@github-actions

This comment has been minimized.

@yordan-st
yordan-st force-pushed the feat/WC-3362_charts-refresh-interval branch from 2422da6 to 02dffb3 Compare October 22, 2026 09:47
@github-actions

This comment has been minimized.

Reloads the given data sources after the interval, restarting the timer on
every data source update and skipping sources that are still loading. Mirrors
the Datagrid 2 / Gallery refresh behaviour. Adds seriesDataSources helper.

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
Add "Refresh time (in seconds)" to the Data source group (default 0 = off).
When set, the chart periodically reloads its data source(s).

Ticket: WC-3362
@yordan-st
yordan-st force-pushed the feat/WC-3362_charts-refresh-interval branch from 02dffb3 to 3b1e150 Compare October 23, 2026 10:58
@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

⚠️ Approved with suggestions — low-severity items only, safe to merge


What was reviewed

File Change
packages/shared/charts/src/hooks/useRefreshInterval.ts New shared hook — timer logic, ref architecture, StrictMode handling
packages/shared/charts/src/hooks/__tests__/useRefreshInterval.spec.ts New unit tests for the hook (9 cases)
packages/shared/charts/src/main.ts Export of new hook and helper
packages/pluggableWidgets/{area,bar,bubble,column,heatmap,line,pie-doughnut,time-series}-chart-web/src/*.tsx Hook call added to each widget component
packages/pluggableWidgets/*/src/*.xml refreshInterval integer property added to all 8 widgets
packages/pluggableWidgets/*/typings/*Props.d.ts refreshInterval added to container and preview prop interfaces
packages/pluggableWidgets/*/src/__tests__/*.spec.tsx refreshInterval: 0 added to test fixtures; integration tests added to LineChart.spec.tsx
packages/pluggableWidgets/*/CHANGELOG.md ### Added entry under [Unreleased] for all 8 widgets
packages/shared/charts/openspec/changes/add-chart-refresh-interval/ OpenSpec design, proposal, spec, tasks artefacts

Skipped (out of scope): dist/, pnpm-lock.yaml

⚠️ Note: gh pr checks was not available in this environment. CI status could not be verified automatically — please confirm all checks are green before merging.


Findings

⚠️ Low — Missing test for negative intervalSeconds

File: packages/shared/charts/src/hooks/__tests__/useRefreshInterval.spec.ts
Note: The spec (spec.md) states "When refreshInterval is 0 or negative, the chart SHALL NOT schedule any automatic reload." The implementation correctly uses intervalSeconds > 0, but there is no test covering a negative value (e.g. -1). Existing tests only cover the 0 case. Adding one is a one-liner and makes the spec compliance explicit.

it("does not reload when interval is negative", () => {
    const ds = new ListValueBuilder().build();
    setup({ datasources: [ds], interval: -1 });
    jest.advanceTimersByTime(60_000);
    expect(ds.reload).not.toHaveBeenCalled();
});

⚠️ Low — No automated E2E spec for the new interactive feature

File: packages/pluggableWidgets/line-chart-web/e2e/ (does not exist for this feature)
Note: Task 5.2 is explicitly left unchecked ("Manual QA in Studio Pro"). The refresh interval is timer-driven and user-visible, which makes it a good candidate for an E2E spec. Not blocking — the unit tests cover all spec-required behaviors comprehensively — but an E2E spec matching the PR's manual test plan would guard against regressions. Consider adding one before the next release.


Positives

  • useRefreshInterval.spec.ts covers all 9 spec-required behaviors (disabled at 0, single fire, multi-source, timer restart on data change, same-datasource no restart, loading-source skip, interval change, StrictMode remount, unmount cancellation). The StrictMode double-invoke case in particular shows careful React 18 awareness.
  • The ref-based architecture (latestRef for the callback, prevDatasourcesRef for change detection) cleanly avoids stale closures without spreading a variable-length array into a useEffect dependency list — the design doc explains the rationale clearly.
  • seriesDataSources is extracted as a separately-tested pure helper, making the per-widget call sites read as a one-liner and keeping the hook API generic.
  • All custom memo comparators (containerPropsEqual, LineChart/TimeSeries/BubbleChart custom flatEqual comparators) use defaultEqual (Object.is) for non-series props, so refreshInterval changes correctly trigger re-renders without any comparator modification.
  • Default refreshInterval = 0 in all XMLs makes the change fully backward-compatible with no migration path needed.
  • XML property key refreshInterval is lowerCamelCase and matches the TypeScript interface exactly across all 8 widgets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants